// 车辆管理 API
import request from '@/utils/request'
import type { ApiResponse, PageResult } from '@/types/api'
import type { Vehicle, VehicleFormData } from '@/types/vehicle'

/**
 * 获取车辆列表
 */
export function getVehicleList(params: {
  current?: number
  size?: number
  vehicleStatus?: string
  keyword?: string
}) {
  return request<ApiResponse<PageResult<Vehicle>>>({
    url: '/tenant/vehicle/list',
    method: 'get',
    params,
  })
}

/**
 * 获取车辆详情
 */
export function getVehicleById(id: number) {
  return request<ApiResponse<Vehicle>>({
    url: `/tenant/vehicle/${id}`,
    method: 'get',
  })
}

/**
 * 创建车辆
 */
export function createVehicle(data: VehicleFormData) {
  return request<ApiResponse<Vehicle>>({
    url: '/tenant/vehicle',
    method: 'post',
    data,
  })
}

/**
 * 更新车辆
 */
export function updateVehicle(id: number, data: VehicleFormData) {
  return request<ApiResponse<null>>({
    url: `/tenant/vehicle/${id}`,
    method: 'put',
    data,
  })
}

/**
 * 解绑司机
 */
export function unbindDriver(id: number) {
  return request<ApiResponse<null>>({
    url: `/tenant/vehicle/${id}/unbind`,
    method: 'post',
  })
}

/**
 * 删除车辆
 */
export function deleteVehicle(id: number) {
  return request<ApiResponse<null>>({
    url: `/tenant/vehicle/${id}`,
    method: 'delete',
  })
}

